/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY. 
 * See the GNU General Public License for more details.
 * 
 * Copyright (C) 2011 CellObject.net
 */
package net.cellobject.javacodeformatter.view;

import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener;
import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;

public final class AltClickCellEditListener extends ColumnViewerEditorActivationListener {
	@Override
	public void beforeEditorActivated(final ColumnViewerEditorActivationEvent event) {
		if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION) {
			if (! (event.sourceEvent instanceof MouseEvent)) {
				event.cancel = true;
			} else {
				final MouseEvent mouseEvent = (MouseEvent)event.sourceEvent;
				if ( (mouseEvent.stateMask & SWT.ALT) == 0) {
					event.cancel = true;
				}
			}
		} else if (event.eventType != ColumnViewerEditorActivationEvent.PROGRAMMATIC) {
			event.cancel = true;
		}
	}

	@Override
	public void afterEditorActivated(final ColumnViewerEditorActivationEvent event) {
	}

	@Override
	public void beforeEditorDeactivated(final ColumnViewerEditorDeactivationEvent event) {
	}

	@Override
	public void afterEditorDeactivated(final ColumnViewerEditorDeactivationEvent event) {
	}
}
